import { Component, OnInit, Input, ElementRef, forwardRef } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
const iconData = ['step-backward', 'step-forward', 'fast-backward', 'fast-forward', 'shrink', 'arrows-alt', 'down',
    'up', 'left', 'right', 'caret-up', 'caret-down', 'caret-left', 'caret-right', 'up-circle', 'down-circle', 'left-circle',
    'right-circle', 'double-right', 'double-left', 'vertical-left', 'vertical-right', 'vertical-align-top', 'vertical-align-middle',
    'vertical-align-bottom', 'forward', 'backward', 'rollback', 'enter', 'retweet', 'swap', 'swap-left', 'swap-right', 'arrow-up',
    'arrow-down', 'arrow-left', 'arrow-right', 'play-circle', 'up-square', 'down-square', 'left-square', 'right-square',
    'login', 'logout', 'menu-fold', 'menu-unfold', 'border-bottom', 'border-horizontal', 'border-inner', 'border-outer', 'border-left',
    'border-right', 'border-top', 'border-verticle', 'pic-center', 'pic-left', 'pic-right', 'radius-bottomleft', 'radius-bottomright',
    'radius-upleft', 'radius-upright', 'fullscreen', 'fullscreen-exit', 'question', 'question-circle', 'plus', 'plus-circle', 'pause',
    'pause-circle', 'minus', 'minus-circle', 'plus-square', 'minus-square', 'info', 'info-circle', 'exclamation', 'exclamation-circle',
    'close', 'close-circle', 'close-square', 'check', 'check-circle', 'check-square', 'clock-circle', 'warning', 'issues-close', 'stop',
    'edit', 'form', 'copy', 'scissor', 'delete', 'snippets', 'diff', 'highlight', 'align-center', 'align-left', 'align-right', 'bg-colors',
    'bold', 'italic', 'underline', 'strikethrough', 'redo', 'undo', 'zoom-in', 'zoom-out', 'font-colors', 'font-size', 'line-height',
    'colum-height', 'dash', 'small-dash', 'sort-ascending', 'sort-descending', 'drag', 'ordered-list', 'unordered-list', 'radius-setting',
    'column-width', 'area-chart', 'pie-chart', 'bar-chart', 'dot-chart', 'line-chart', 'radar-chart', 'heat-map', 'fall', 'rise', 'stock',
    'box-plot', 'fund', 'sliders', 'android', 'apple', 'windows', 'ie', 'chrome', 'github', 'aliwangwang', 'dingding', 'weibo-square',
    'weibo-circle', 'taobao-circle', 'html5', 'weibo', 'twitter', 'wechat', 'youtube', 'alipay-circle', 'taobao', 'skype', 'qq',
    'medium-workmark', 'gitlab', 'medium', 'linkedin', 'google-plus', 'dropbox', 'facebook', 'codepen', 'code-sandbox', 'amazon', 'google',
    'codepen-circle', 'alipay', 'ant-design', 'ant-cloud', 'aliyun', 'zhihu', 'slack', 'slack-square', 'behance', 'behance-square',
    'dribbble', 'dribbble-square', 'instagram', 'yuque', 'alibaba', 'yahoo', 'reddit', 'sketch', 'account-book', 'alert', 'api', 'appstore',
    'audio', 'bank', 'bell', 'book', 'build', 'bulb', 'calculator', 'calendar', 'car', 'camera', 'carry-out', 'cloud', 'code',
    'compass', 'contacts', 'container', 'control', 'credit-card', 'crown', 'customer-service', 'dashboard', 'database', 'dislike',
    'environment', 'experiment', 'eye-invisible', 'eye', 'file-add', 'file-exclamation', 'file-excel', 'file-image', 'file-markdown',
    'file-pdf', 'file-ppt', 'file-text', 'file-unknown', 'file-word', 'file-zip', 'file', 'filter', 'fire', 'flag', 'folder-add',
    'folder-open', 'folder', 'frown', 'funnel-plot', 'gift', 'hdd', 'heart', 'home', 'hourglass', 'idcard', 'insurance',
    'layout', 'like', 'lock', 'mail', 'medicine-box', 'meh', 'message', 'mobile', 'money-collect', 'notification', 'pay-circle', 'phone',
    'picture', 'play-square', 'printer', 'profile', 'project', 'property-safety', 'pushpin', 'read', 'reconciliation', 'red-envelope',
    'rest', 'rocket', 'safety-certificate', 'save', 'schedule', 'security-scan', 'setting', 'shop', 'shopping', 'skin', 'smile', 'sound',
    'star', 'switcher', 'tablet', 'tags', 'tag', 'thunderbolt', 'tool', 'trophy', 'unlock', 'usb', 'video-camera', 'wallet', 'apartment',
    'audit', 'barcode', 'bars', 'block', 'border', 'branches', 'ci', 'cloud-download', 'cloud-server', 'cloud-sync', 'cloud-upload',
    'cluster', 'coffee', 'copyright', 'desktop', 'deployment-unit', 'disconnect', 'dollar', 'download', 'ellipsis', 'euro', 'exception',
    'file-done', 'file-jpg', 'file-protect', 'file-search', 'file-sync', 'fork', 'gateway', 'global', 'gold', 'inbox', 'key',
    'laptop', 'line', 'link', 'loading-3-quarters', 'loading', 'man', 'menu', 'monitor', 'number', 'paper-clip', 'percentage',
    'pound', 'poweroff', 'qrcode', 'reload', 'robot', 'safety', 'scan', 'search', 'select', 'shake', 'share-alt',
    'shopping-cart', 'solution', 'sync', 'table', 'team', 'to-top', 'trademark', 'transaction', 'upload', 'user-add', 'user-delete', 'user',
    'usergroup-add', 'usergroup-delete', 'wifi', 'woman'
];
@Component({
    template: `
        <button nz-button nzType="primary" (click)="open()">选择图标</button>
        <i nz-icon *ngIf="value" [nzType]="value" nzTheme="outline"></i>
        <nz-drawer [nzWidth]="400" [nzClosable]="false" [nzVisible]="showBox" nzPlacement="right" nzTitle="选择图标" (nzOnClose)="close()">
            <div nz-row nzType="flex" nzJustify="start" [nzGutter]="8">
                <div (click)="select(icon)" nz-col nzSpan="4" *ngFor="let icon of data; let i = index">
                    <div
                    style="text-align:center;border-radius:4px;transition:all 0.3s;font-size:18px;padding:4px 0;margin:5px 0;"
                    [ngStyle]="{'background-color':value===icon?'#00aaff':'#fff',color:value===icon?'#fff':'#111'}">
                        <i nz-icon [nzType]="icon" nzTheme="outline"></i>
                    </div>
                </div>
            </div>
        </nz-drawer>
    `,
    selector: "clain-select-icon",
    providers: [
        {
            provide: NG_VALUE_ACCESSOR,
            useExisting: forwardRef(() => ClainSelectIconComponent),
            multi: true,
        },
    ],
})
export class ClainSelectIconComponent implements OnInit, ControlValueAccessor {
    constructor(private el: ElementRef) {}
    @Input()
    private value: string;
    private showBox: Boolean = false;
    private data: Array<string> = iconData;
    propagateChange = (_: any) => {};
    writeValue(value: string) {
        if (value) {
            this.value = value;
        }
    }
    registerOnChange(fn: any) {
        this.propagateChange = fn;
    }

    registerOnTouched(fn: any) {}
    open() {
        this.showBox = true;
    }
    close() {
        this.showBox = false;
    }
    select(item) {
        this.value = item;
        this.propagateChange(item);
    }
    ngOnInit() {}
}
